<script setup lang="ts">
import { ref } from 'vue'
import { get, post } from '@/utils/service'
import { VUE_APP_BASE_API } from '@/utils/baseConfig'
const member = ref({})
const noEmpty = ref(false)
queryCarMasterWechat()
function onClickLeft() {
  window.history.back()
}

function queryCarMasterWechat() {
  // 异步更新数据
  // setTimeout 仅做示例，真实场景中一般为 ajax 请求
  get('/memberWechatNew/queryMemberWehcat', {})
    .then((res) => {
      if (res.code === 0) {
        member.value = res.data
      } else {
      }
    })
    .catch((err) => {
      console.log(err)
    })
}
const receptionLists = ref([])
const loading = ref(false)
const finished = ref(false)

const page = ref(1)
const limit = 10
function onLoad() {
  queryData()
}
function queryData() {
  // 异步更新数据
  // setTimeout 仅做示例，真实场景中一般为 ajax 请求
  get('/receptionWechatNew/queryMyReceptionWechat', {
    limit: limit,
    page: page.value,
  })
    .then((res) => {
      if (res.code === 0) {
        // 正常返回数据
        loading.value = false
        noEmpty.value = false
        res.data.forEach((item) => {
          receptionLists.value.push({
            ...item,
          })
        })
        if (page.value == res.totalPage) {
          loading.value = true
          finished.value = true
          noEmpty.value = false
        } else {
          page.value++
        }
      } else {
        //其他返回数据情况
        if (res.count > 0) {
          //有数据情况
          if (res.code == 201) {
            loading.value = true
            finished.value = true
            noEmpty.value = false
          }
        } else {
          //无数据情况
          loading.value = true
          finished.value = true
          noEmpty.value = true
        }
      }
    })
    .catch((err) => {
      console.log(err)
    })
}
</script>
<template>
  <van-nav-bar title="保养记录" left-text="返回" left-arrow @click-left="onClickLeft" />
  <van-empty
    v-if="member.carMasterStatus == 1"
    :image="VUE_APP_BASE_API + '/images/vue/noData.png'"
    image-size="100"
    description="还未绑定车主"
  />
  <div class="mainContent" v-if="member.carMasterStatus == 1">
    <div style="width: 100%; padding: 12px">
      <van-button type="primary" style="width: 100%" to="/carMasterInfo">绑定车辆</van-button>
    </div>
  </div>
  <van-empty
    v-if="member.carMasterStatus == 2 && noEmpty == true"
    :image="VUE_APP_BASE_API + '/images/vue/noData.png'"
    image-size="100"
    description="当前无保养记录"
  />
  <van-list
    v-else
    v-model:loading="loading"
    :finished="finished"
    finished-text="没有更多了"
    @load="onLoad"
  >
    <div class="memberCarContent" v-for="reception in receptionLists" :key="reception.dbid">
      <div class="memberCardHeader">
        <div class="memberCardTitle">{{ reception.repairTypeName }}</div>
        <div class="rightText"></div>
      </div>
      <van-cell-group>
        <van-cell title="进站时间" :value="reception.repairTime" style="va" />
        <van-cell title="保养内容" :value="reception.repItems" />
        <van-cell title="车型" :value="reception.carSeriyName" />
        <van-cell title="车牌号" :value="reception.carPlateNo" />
        <van-cell title="服务顾问" :value="reception.serviceName" />
      </van-cell-group>
    </div>
    <br />
  </van-list>
  <br />
</template>
<style lang="css">
.van-hairline--top-bottom:after,
.van-hairline-unset--top-bottom:after {
  border-width: 0ch;
}
</style>
